<template>
	<view class="root">
		<view class="">
			<u-tag text="获奖证明上传" shape="circleRight" />
		</view>
		<view style="margin-top: 10px;">
			<uni-file-picker v-model="imageValue" title="" :auto-upload="true" limit="9" file-mediatype="image"
				@success="upSuccess" @delete="deletepic"></uni-file-picker>

		</view>

		<!-- <view style="margin-top: 10px;" class="">
			<u-button @click="submit">保存</u-button>
		</view> -->

		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageValue: [],
					selectFiles: [],
					picList: [],
					dateShow: false,
					form2: {

					}
				}
			},
			methods: {

					submit() {

					},
					upSuccess(e) {
						// console.log(this.imageValue)
						this.selectFiles = this.imageValue
						uni.setStorage({
							key:'pic',
							data:{
								files:this.selectFiles,
								picNum:this.selectFiles.length
							}
						})
						// this.$refs.uToast.show({
						// 	title: '上传成功',
						// 	type: 'success',
						// })
					},
					deletepic(e) {

						uni.showLoading({
							title: '正在删除'
						})
						
						uniCloud.callFunction({
							name: 'deletepic',
							data: {
								fileid: e.tempFilePath
							}
						}).then(() => {
							uni.hideLoading()
							this.selectFiles = this.imageValue
							uni.setStorage({
								key:'pic',
								data:{
									files:this.selectFiles,
									picNum:this.selectFiles.length
								}
							})
							console.log(this.imageValue)
						}).catch(()=>{
							uni.hideLoading()
							this.selectFiles = this.imageValue
							uni.setStorage({
								key:'pic',
								data:{
									files:this.selectFiles,
									picNum:this.selectFiles.length
								}
							})
						})
					}

				},
				onShow() {
					uni.getStorage({
						key:'pic',
						success: (res) => {
							this.imageValue = res.data.files
						}
					})
				}
		}
</script>

<style>
	.root {
		padding: 20px;
		background-color: #ffffff;
	}
</style>
